import axios from 'axios'

const http = axios.create({
    baseURL: 'http://127.0.0.1:5862',
    // baseURL: 'http://124.223.31.209:5862',
    timeout: 5000
})

http.interceptors.request.use(config => {
    const token = localStorage.getItem('BOOK_M_TOKEN')
    if(config.url.indexOf('/admin') !== -1){
        config.headers.Authorization = 'Bearer ' + token
    }
    return config
})

async function $http(option){
    return http({
        method: option.method,
        url: option.url,
        [option.method.toLowerCase() === 'get' ? 'params' : 'data']: option.data
    })

}

export default $http
